package com.mingle.iwalk;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class LogingActivity extends Activity {

	public static final String SETTING_INFOS = "SETTING_Infos";
	public static final String NAME = "NAME"; 
    public static final String PASSWORD = "PASSWORD"; 
    
    private EditText mUserName;
    private EditText mPassword;
	 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.loging_layout);
        
        Button exitBtn = (Button) findViewById(R.id.exit_btn);
        exitBtn.setOnClickListener(mExitListener);
        
        mUserName = (EditText) findViewById(R.id.user_name);
        mPassword = (EditText) findViewById(R.id.user_pswd);
        SharedPreferences settings = getSharedPreferences(SETTING_INFOS, 0); 
        String name = settings.getString(NAME, "");
        String password = settings.getString(PASSWORD, "");
        
        if(name.length() != 0)
        {
        	mUserName.setText(name);
        }
        
        if(password.length() != 0)
        {
        	mPassword.setText(password);
        }
        
        Button loginBtn = (Button) findViewById(R.id.login_btn);
        loginBtn.setOnClickListener(new OnClickListener()
        {

			@Override
			public void onClick(View v) {
				String strName = mUserName.getText().toString();
				String strPwd = mPassword.getText().toString();
				if(strName!=null&&strName.length()!=0&&strPwd!=null&&strPwd.length()!=0)
				{
					SharedPreferences settings = getSharedPreferences(SETTING_INFOS, 0); 
			        settings.edit() 
			            .putString(NAME, strName)
			            .putString(PASSWORD, strPwd) 
			            .commit(); 
				}
				
			}
        	
        });
        
    }
    
	private OnClickListener mExitListener = new OnClickListener()
	{

		@Override
		public void onClick(View v) {
			finish();
		}
		
	};
	
	private Context getContext()
    {
    	return LogingActivity.this;
    }
}
